﻿using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Stamp_For_Africa_Version_2.Models
{
	[Bind(Include="Name,Surname,IsDefault")]
  public partial class Artist
  {
    public bool IsValid
    {
      get { return (GetRuleViolations().Count() == 0); }
    }

    public IEnumerable<RuleViolation> GetRuleViolations()
    {
      if (String.IsNullOrEmpty(Name))
        yield return new RuleViolation("Artist's name required", "Name");

      if (String.IsNullOrEmpty(Surname))
        yield return new RuleViolation("Artist's surname required", "Surname");

      yield break;
    }

    partial void OnValidate(ChangeAction action)
    {
      if (!IsValid)
        throw new ApplicationException("Rule violations prevent saving");
    }

		public override string ToString()
		{
			if (Name == "UNKNOWN")
				return Name;
			else
				return Name + " " + Surname;
		}

		public string DisplayName
		{
			get { return Name + " " + Surname; }				
		}

    public bool HasImage { get { return Image == null; } }
  }
}